package com.cze.service.impl;

import com.cze.mapper.ProductMapper;
import com.cze.service.ProductSerivce;
import com.cze.vo.Product;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductSerivceImpl implements ProductSerivce{

    private ProductMapper productMapper;

    @Resource(name = "productMapper")
    public void setproductMapper(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }

    @Override
    public boolean modify(Product product) {
        return productMapper.update(product) == 1;
    }

    @Override
    public boolean add(Product product) {
        return productMapper.add(product) == 1;
    }

    @Override
    public boolean delete(int productID) {
        return productMapper.delelte(productID) == 1;
    }

    @Override
    public List<Product> getProducts(int page, int limit) {
        return productMapper.selectPage(page*limit,limit);
    }

    @Override
    public int countAll() {
        return productMapper.countAll();
    }

    @Override
    public List<Product> search(String keyword) {
        return productMapper.findByKeyWord(keyword);
    }

    @Override
    public Product findByID(int productID) {
        return productMapper.findByID(productID);
    }
}
